package com.custom.common.sha256;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * @ClassName: RequestHelper
 * @description:
 * @author: liukui
 * @date: 2018/11/17 16:07
 * @version: 1.0
 */
public class RequestHelper {
    public RequestHelper() {
    }

    public static Boolean verifyMd5(HttpServletRequest request, String secretKey) {
        return Md5Verify.verifyMd5(getRequestMap(request), secretKey);
    }

    public static Map<String, String> getRequestMap(HttpServletRequest request) {
        Map<String, String> requestParames = new HashMap();
        if(null != request) {
            Set<String> keys = request.getParameterMap().keySet();
            Iterator i$ = keys.iterator();

            while(i$.hasNext()) {
                String key = (String)i$.next();
                requestParames.put(key, request.getParameter(key));
            }
        }

        return requestParames;
    }

    public static String getAllParames(HttpServletRequest request) {
        return createLinkString(getRequestMap(request));
    }

    private static String createLinkString(Map<String, String> params) {
        String result = "";

        Map.Entry entry;
        for(Iterator i$ = params.entrySet().iterator(); i$.hasNext(); result = result + (String)entry.getKey() + "=" + (String)entry.getValue() + "&") {
            entry = (Map.Entry)i$.next();
        }

        return result;
    }
}
